package com.xiangyang.controller;

import com.xiangyang.entity.Role;
import com.xiangyang.entity.dto.Result;
import com.xiangyang.service.impl.RoleServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/Role")
@CrossOrigin
public class RoleController {
    @Autowired
    private RoleServiceImpl rsi;

    @GetMapping("/addRole")
    @PreAuthorize("hasAnyAuthority('sys:employee')")
    // 添加角色
    public Result addRole(@RequestBody Role role){
        // 调用service层添加角色
        return rsi.addRole(role);
    }

    @DeleteMapping("/deleteRole")
    @PreAuthorize("hasAnyAuthority('sys:employee')")
    public Result deleteRole( Long roleId){
        return rsi.deleteRole(roleId);
    }

    @GetMapping("/getRoleList")
    public Result getRoleList(){
        return rsi.getRoleList();
    }

    @PutMapping("/updateRole")
    @PreAuthorize("hasAnyAuthority('sys:employee')")
    public Result updateRole(@RequestBody Role role){
        return rsi.updateRole(role);
    }

}